#include<iostream>
#include<stack>
using namespace std;
struct TreeNode {
     int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 };
 
class Solution {
public:
    stack<int>st;
    int inorder(TreeNode*root)
    {
        if(root==NULL)return NULL;
        inorder(root->left);
        st.push(root->val);
        inorder(root->right);
        return 0;
    }
    bool isValidBST(TreeNode* root) {
        inorder(root);
        int tmp=st.top();
            st.pop();
        while(!st.empty())
        {
            int tmp1=st.top();
            st.pop();
            if(tmp>tmp1)
            {
                tmp=tmp1;
            }
            else return false;
            
        }
        return true;

    }
};
